﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace _3_2_使用编辑器添加删除项目
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs ex)
        {
            ListViewItem item1 = new ListViewItem();
            item1.Text = "lili";
            item1.SubItems.Add("G6");
            item1.SubItems.Add("18");
            item1.SubItems.Add("物化地");
            listView1.Items.Add(item1);
            ListViewItem item2 = new ListViewItem();
            item2.Text = "chengzi";
            item2.SubItems.Add("G6");
            item2.SubItems.Add("18");
            item2.SubItems.Add("物化地");
            listView1.Items.Add(item2);
            ListViewItem item3 = new ListViewItem("Hinder");
            item3.SubItems.Add("G6");
            item3.SubItems.Add("18");
            item3.SubItems.Add("物化地");
            listView1.Items.Add(item3);
            //listView1.Items.Remove(item3);
        }

        private void listView1_DoubleClick(object sender, EventArgs e)
        {
            foreach (ListViewItem item in listView1.Items)
            {
                if (item.Selected == true)
                {
                    MessageBox.Show($"{item.Text},{item.SubItems[1].Text},{item.SubItems[2].Text},{item.SubItems[3].Text}");
                }
            }
        }

        private void 删除ToolStripMenuItem_Click(object sender, EventArgs e)
        {
           ListView.SelectedListViewItemCollection list = this.listView1.SelectedItems;
            //MessageBox.Show(list.Count.ToString());
            if (list.Count == 0) {
                return;
            }
            foreach (var items in list)
            {
                
                this.listView1.Items.Remove(items as ListViewItem);
            }
        }

        private void 大图标ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.listView1.View = View.List;
        }

        private void 详细ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.listView1.View = View.Details;
        }
    }
}
